package response

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

// 通用数据返回
func Response(ctx *gin.Context, httpStatus int, code int, data gin.H, msg string) {
	if data["data"] != nil {
		ctx.JSON(httpStatus, gin.H{"code": code, "data": data["data"], "msg": msg})
	} else {
		ctx.JSON(httpStatus, gin.H{"code": code, "data": data, "msg": msg})
	}
	ctx.Abort()
}

// 成功返回
func Success(ctx *gin.Context, data gin.H, msg string) {
	Response(ctx, http.StatusOK, 0, data, msg)
}

// 失败返回
func Fail(ctx *gin.Context, data gin.H, msg string) {
	Response(ctx, http.StatusOK, -4000000, data, msg)
}
